package com.sense.kukoo.biz_explore.adapter

import com.sense.kukoo.biz_explore.adapter.provider.IndexContentItemProvider
import com.sense.kukoo.biz_explore.adapter.provider.IndexFooterItemProvider
import com.sense.kukoo.biz_explore.adapter.provider.IndexHeaderItemProvider
import com.sense.kukoo.common.media.bean.LocalMediaListItemBean
import com.sense.kukoo.common.media.watcher.UserWatcher
import com.sense.kukoo.common.repo.biz.ExploreContentBean
import com.sense.kukoo.common.repo.http.bean.IndexContentBean
import com.sense.kukoo.common.wiget.adapter.MultiItemAdapter

class IndexContentAdapter(
    val data:List<ExploreContentBean>,
    val listener:IndexContentEventListener,
): MultiItemAdapter<ExploreContentBean>(data) {

    val mIndexContentItemProvider: IndexContentItemProvider

    var mCurrentMusic: LocalMediaListItemBean? = null
    var mCurrentPlayState: Int = UserWatcher.MusicStateWatcher.STATE_NOT_PLAYING

    init {
        mIndexContentItemProvider = IndexContentItemProvider(listener)
        //
        addItemProvider(IndexHeaderItemProvider())
        addItemProvider(mIndexContentItemProvider)
        addItemProvider(IndexFooterItemProvider())
    }

    override fun getItemType(data: MutableList<ExploreContentBean>?, position: Int): Int {
        return data?.get(position)?.type ?: ExploreContentBean.TYPE_DEF
    }

    interface IndexContentEventListener{
        fun onItemClick(data: IndexContentBean)
        fun onChannelClick(data: IndexContentBean)
        fun onBtnPlayClick(data: IndexContentBean)
    }

    fun setCurrentMusic(music: LocalMediaListItemBean){
        mCurrentMusic = music
        //
        mIndexContentItemProvider.setCurrentMusic(music)
        notifyDataSetChanged()
    }

    fun setCurrentPlayState(state: Int){
        mCurrentPlayState = state
        //
        mIndexContentItemProvider.setCurrentPlayState(state)
        notifyDataSetChanged()
    }

}